# 部门增删改查
import requests

from common.get_token import get_token


class DEPTCURDAPI():
    # 查询部门
    @classmethod
    def query_dept(cls, dept_id, token):
        resp = requests.get(url=f"http://ihrm2-test.itheima.net/api/company/department/{dept_id}",
                            headers={"Authorization": token})
        return resp

    # 增加部门
    @classmethod
    def add_dept(cls, token, data):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/company/department",
                             headers={"Content-Type": "application/json",
                                      "Authorization": token},
                             json=data)
        return resp

    # 修改部门
    @classmethod
    def modify_dept(cls, dept_id, token, data):
        resp = requests.put(url=f"http://ihrm2-test.itheima.net/api/company/department/{dept_id}",
                            headers={"Content-Type": "application/json",
                                     "Authorization": token},
                            json=data)
        return resp

    # 删除部门
    @classmethod
    def del_dept(cls, dept_id, token):
        resp = requests.delete(url=f"http://ihrm2-test.itheima.net/api/company/department/{dept_id}",
                               headers={"Authorization": token})
        return resp


if __name__ == '__main__':
    token = get_token()
    data = {"name": "狮心会", "code": "654321"}
    res = DEPTCURDAPI.add_dept(token, data)
    a = type(res.json().get("data").get("id"))
    print(res.json().get("data").get("id"), a )

# id = "1571715979082330112"
# res = DEPTCURDAPI.query_dept(id, token)
# print(res.json())

# data = {"name": "狮心会", "code": "654322"}
# res = DEPTCURDAPI.modify_dept(id, token, data)
# print(res.json())
# id = "1571717550193111040"
# res = DEPTCURDAPI.del_dept(id, token)
# print(res.json())
#
# res = DEPTCURDAPI.query_dept(id, token)
#
# print(res.json())
